<template>
	<view>
		<!-- <view class="'navBar"><text class="navTitle">实名认证</text></view> -->

		<view class="tip">根据国家要求规定，上门护理服务需进行身份</view>
		<view class="positive">
			<view class="left"></view>人脸验证
		</view>

		<view class="face" style="background: url(../../../static/img/iden/face.png);background-size: 208rpx 208rpx ;">
			<image :src="src" mode="" style="width: 208rpx;
			 height: 206rpx;"></image>
		</view>

		<view class="positive">
			<view class="left"></view>拍摄须知
		</view>
		<view class="demo" v-if="demo.length>0">
			<view class="demo1" v-for="(item,index) in demo" :key="index">
				<image :src=" item.src " mode=""></image>

				<view class="demo2"><text :style="item.style">{{item.judge}}</text>{{item.txt}}</view>
			</view>
		</view>

		<view class="into">
			<view class="save" style="background-color:#3c8eff ;" @click="save">开始录入</view>
		</view>
	</view>
</template>

<script>
	import {
		idCardCheck
	} from '@/apis/nurse/index.js'
	import {
		selectNurseInfoCheckById,
	} from '@/apis/certificate/certification.js'
	import uploadImage from '@/common/js/ossutil/uploadFile.js';
	import {
		requestAndroid
	} from '@/common/js/location.js'
	export default {
		data() {
			return {
				num: 0, //0可点击
				src: '',
				cardSrc: '',
				cardSrcBack: '',
				demo: [{
						src: "../../../static/img/iden/right.png",
						style: `color: #3c8eff;`,
						judge: '√',
						txt: "标准拍摄"
					},
					{
						src: "../../../static/img/iden/wrong1.png",
						style: `color: rgba(255, 79, 79, 1);`,
						judge: '×',
						txt: "遮挡脸部"
					},
					{
						src: "../../../static/img/iden/wrong2.png",
						style: `color: rgba(255, 79, 79, 1);`,
						judge: '×',
						txt: "拍摄不全"
					},
					{
						src: "../../../static/img/iden/wrong3.png",
						style: `color: rgba(255, 79, 79, 1);`,
						judge: '×',
						txt: "光线不足"
					}
				],

			}
		},
		onLoad(option) {
			if (JSON.parse(option.data)) {
				let data = JSON.parse(decodeURIComponent(option.data)) 
				console.log(data.cardSrcBack)
				this.cardSrc = data.cardSrc
				this.cardSrcBack = data.cardSrcBack
			}


		},
		onShow() {
			this.select()
		},

		methods: {

			save() {
				if (this.num == 1) {
					plus.nativeUI.toast('您已在进行验证')
					// uni.showToast({
					// 	icon:'none',
					// 	title:'您已在进行验证',
					// })
					// uni.navigateTo({
					// 	url: '../iden/careerChoice'
					// })
				} else {
					this.num++
					let _this = this
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album', 'camera'], //从相册选择 拍照
						success: function(res) {
							let tempFiles = res.tempFilePaths[0];
							_this.src = tempFiles
							uploadImage(tempFiles, 'idCardNurse/',
								async function(result) {
									let res = await idCardCheck({
										idCard: _this.cardSrc,
										face: result,
										negativeIdentity: _this.cardSrcBack
									})
									if (res.success) {
										uni.setStorageSync('tab', 1)
										_this.$store.commit('setNameStatus', true)
										_this.num = 0
										plus.nativeUI.toast('上传成功')
										// uni.showToast({
										// icon:'success',
										// title:'上传成功',
										//   })
										setTimeout(() => {
											// uni.navigateBack({
											// 	delta: 1
											// })
											uni.navigateTo({
												url: '../iden/careerChoice'
											})
											// uni.switchTab({
											// 	url:'../../tabbars/mine/mine'
											// })
										}, 300)
									} else {
										_this.num = 0
										// let pages = getCurrentPages();
										// let prevPage = pages[pages.length - 2]; //上一个页面
										// prevPage.setData({
										// mdata:1
										// })
										setTimeout(() => {
											uni.navigateBack({
												delta: 1
											})
										}, 500)
									}
								}, error => {
									_this.num = 0
									plus.nativeUI.toast('上传失败')
									// uni.showToast({
									// 	icon:'none',
									// 	title:'上传失败',
									// })

								})
						},
						fail(e) {
							_this.num = 0
							if (e.errCode == 11) {
								requestAndroid('android.permission.CAMERA', '摄像头')
							}
							// console.log(e,'shibaihuid........')
						}
					});
				}
			},
			//获取验证信息
			async select() {
				let id = this.$store.state.userInfo.id
				let res = await selectNurseInfoCheckById({
					id
				})
				console.log('hushirenz', res)
				if (res.success) {
					if (res.object.faceJson) {
						this.src = res.object.faceJson
						this.num = 1
					}

				}
			},
		}
	}
</script>

<style scoped lang="less">
	.navBar {
		width: 100%;
		height: 176rpx;
		background: #3C8EFF;
		padding-left: 308rpx;
		padding-top: 108rpx;
		// filter: blur(10px);
		box-sizing: border-box;

		.navTitle {
			width: 136rpx;
			height: 48rpx;
			font-size: 34rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #ffffff;
			line-height: 48rpx;
		}
	}

	.tip {
		width: 100%;
		height: 72rpx;
		background: rgba(255, 106, 0, 0.1);
		// opacity: 0.1;
		font-size: 28rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #FF6A00;
		line-height: 72rpx;
		text-align: center;
	}

	.positive {
		width: 698rpx;
		height: 108rpx;
		background: #FFFFFF;

		display: flex;
		align-items: center;
		box-sizing: border-box;
		border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
		margin-left: 26rpx;
		// line-height: 108rpx;
		// padding-top: 34rpx;
		font-size: 32rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		- color: rgba(0, 0, 0, 0.87);

		.left {
			width: 8rpx;
			height: 40rpx;
			background: #3C8EFF;
			border-radius: 4rpx;
			margin-right: 16rpx;
		}
	}

	.face {
		width: 208rpx;
		height: 206rpx;
		// border: 1rpx dashed rgba(51,51,51,0.6);
		margin-top: 70rpx;
		margin-left: 272rpx;
		margin-bottom: 70rpx;
	}


	.demo {
		padding-top: 58rpx;
		// height:176rpx;
		height: 234rpx;
		// width:698rpx;
		width: 100%;

		padding-left: 26rpx;
		padding-right: 36rpx;
		display: flex;
		justify-content: space-between;
		box-sizing: border-box;

		// margin-bottom: 190rpx;
		.demo1 {
			image {
				width: 120rpx;
				height: 120rpx;
			}

			.demo2 {
				width: 120rpx;
				height: 34rpx;
				font-size: 24rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #354052;
				line-height: 34rpx;
			}
		}
	}

	.into {
		width: 100%;
		height: 144rpx;
		background: rgba(216, 216, 216, 0);
		display: flex;
		justify-content: space-around;
		align-items: center;
		// margin-top: 368rpx;
		position: fixed;
		bottom: 0;
		box-shadow: 0rpx -6rpx 8rpx 0rpx rgba(0, 0, 0, 0.03);

		.save {
			width: 698rpx;
			height: 96rpx;
			line-height: 96rpx;
			text-align: center;
			background: rgba(202, 247, 249, 1);
			// #3c8effdius: 8rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}
	}
</style>